// CountryServiceImpl.java (服务实现类)
package com.ywb.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ywb.mapper.CountryMapper;
import com.ywb.pojo.Country;
import com.ywb.pojo.CountryQueryParam;
import com.ywb.pojo.PageResult;
import com.ywb.service.CountryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CountryServiceImpl implements CountryService {

    @Autowired
    private CountryMapper countryMapper;

    @Override
    public List<Country> findAll() {
        return countryMapper.findAll();
    }

    @Override
    public void deleteById(Integer id) {
        countryMapper.deleteById(id);
    }

    @Override
    public void add(Country country) {
        countryMapper.insert(country);
    }

    @Override
    public Country getById(Integer id) {
        return countryMapper.getById(id);
    }

    @Override
    public void update(Country country) {
        countryMapper.update(country);
    }

    @Override
    public PageResult<Country> page(CountryQueryParam countryQueryParam) {
        PageHelper.startPage(countryQueryParam.getPage(), countryQueryParam.getPageSize());
        List<Country> countries = countryMapper.list(countryQueryParam);
        Page<Country> p= (Page<Country>) countries;
        return new PageResult<>(p.getTotal(),p.getResult());
    }
}